<?php
namespace App\Services\Admin;

use App\Repositories\Admin\ActionRepository;

class ActionService
{
    private $service;

    public function __construct()
    {
        $this->service = new ActionRepository();
    }

    public function getIndex($moduleId)
    {
        $models = $this->service->getIndexList($moduleId);
        foreach ($models as $model) {
            $model->subs = $this->service->getSubsList($model->id);
        }
        return $models;
    }

    public function getModules($moduleId=2)
    {
        $modules = $this->service->getModuleList($moduleId);
        foreach ($modules as $module) {
            $module->subs = $this->service->getSubsList2($module->id);
        }
        return $modules;
    }

    public function getParents($moduleId)
    {
        return $this->service->getParentList($moduleId);
    }

    public function getForms()
    {
        $models = $this->service->getHomeSub();
        $dataArr = array();
        foreach ($models as $model) {
            $dataArr[$model->id] = $model->name;
            $model2s = $this->service->getSubsList($model->id);
            if (count($model2s)) {
                foreach ($model2s as $model2) {
                    $dataArr[$model2->id] = $model->name.'--'.$model2->name;
                }
            }
        }
        return $dataArr;
    }

    public function add($data)
    {
        return $this->service->setAdd($data);
    }

    public function modify($data,$id)
    {
        return $this->service->setModify($data,$id);
    }

    public function setDel($id)
    {
        return $this->service->setDel($id);
    }

    public function setDelRedo($id)
    {
        return $this->service->setDelRedo($id);
    }

    public function getOne($id)
    {
        return $this->service->getShowOne($id);
    }

    public function getHome()
    {
        return $this->service->getHome();
    }

    public function getHomeSub()
    {
        return $this->service->getHomeSub();
    }
}